package com.fruit.controller.app.order;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fruit.controller.base.BaseController;
import com.fruit.pojo.order.MyOrder;
import com.fruit.pojo.order.OrderGoods;
import com.fruit.service.order.OrderManager;
import com.fruit.util.DateUtil;
import com.fruit.util.ResultInfo;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Controller
@RequestMapping(value = "/app/order")
public class OrderControllerApp extends BaseController  {

	
	@Autowired
	private OrderManager orderManager;
	
	/**
	 * 我的订单
	 * 
	 * @param userId
	 *            userId
	 * @param page
	 *            page
	 * @param showNum
	 *            showNum
	 * @param request
	 *            request
	 * @param session
	 *            session
	 * @return Map<String, Object>
	 * @author 葛欢欢
	 * @version 2017.11.30 12:20
	 */
	@RequestMapping(value = "/myOrder", method = { RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public Map<String, Object> myOrder(String userId, int page, int showNum, HttpServletRequest request,
			HttpSession session) {
		long a = System.currentTimeMillis();
		log.info("【我的订单进入时间】" + DateUtil.getTime());
		log.info("【我的订单】---【开始】---");
		Map<String, Object> resultMap = new HashMap<String, Object>();
		Map<String, Object> pam = new HashMap<String, Object>();
		pam.put("userId", userId);
		pam.put("start", (page - 1) * showNum);
		pam.put("number", showNum);
		try {
			// 我的订单列表	
			List<MyOrder> myOrder = orderManager.getMyOrderByUserId(pam);
			resultMap.put("myOrder", myOrder);
			resultMap.put("result", this.initResult(ResultInfo.SUCCESS, "ok", ""));
		} catch (Exception e) {
			e.printStackTrace();
			log.info("【我的订单】---【查询错误】---");
			resultMap.put("result", this.initResult(ResultInfo.ERROR, "exception", "系统异常"));
		}

		log.info("【我的订单】---【结束】---");
		log.info("【我的订单耗时】" + (System.currentTimeMillis() - a) / 1000f + "秒");
		return resultMap;
	}
}
